package io.github.eric.urpc.core.serializer;

public enum Serializer {
    Json("json", new JsonMessageSerializer()),
    ;

    private final String type;
    private final MessageSerializer serializer;

    Serializer(String type, MessageSerializer serializer) {
        this.type = type;
        this.serializer = serializer;
    }

    public String getType() {
        return type;
    }

    public MessageSerializer getSerializer() {
        return serializer;
    }

    public static Serializer fromType(String type) {
        for (Serializer st : Serializer.values()) {
            if (st.type.equals(type)) {
                return st;
            }
        }
        throw new IllegalArgumentException("can not find any serializer from type '" + type + "'");
    }
}
